package cn.rongdao.jrkabao.ui.main.mainfragment.uicomponent;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mifengkong.frtools.util.FRCollection;
import com.mifengkong.frtools.util.FRString;

import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.bean.main.vip.MemberBean;

/**
 * Created by jack on 2018/1/25
 */

public class ItemVipUIComponent extends FrameLayout {
    public ItemVipUIComponent(Context context) {
        super(context);
    }

    public ItemVipUIComponent(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ItemVipUIComponent(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private RelativeLayout rlMain;
    private TextView tvTitle;
    private TextView tvTip;

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        rlMain = findViewById(R.id.iv_rl_main);
        tvTitle = findViewById(R.id.iv_tv_title);
        tvTip = findViewById(R.id.iv_tv_tip);
    }

    public void setContent(MemberBean.VipConfigBean data) {
        rlMain.setEnabled(!data.isSelect());
        setTitle(data.getTitle(), data.getPrice());
        tvTip.setText(FRString.valueOf(data.getDesc()));
    }

    private void setTitle(String title, String price) {
        if (FRString.isEmpty(title, price)) {
            return;
        }
        String content = FRCollection.appendAsString(title, "\n￥", price, "");
        SpannableString ss = new SpannableString(content);
        ss.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.cff7048)), title.length(), content.length()
                , Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        ss.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, title.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        ss.setSpan(new AbsoluteSizeSpan(16, true), title.length(), content.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        tvTitle.setText(ss);
    }
}
